package com.shujia.spark.core

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object Demo15MapValue {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf()
    conf.setMaster("local")
    conf.setAppName("join")

    val sc = new SparkContext(conf)

    val idAndAgeRDD: RDD[(String, Int)] = sc.parallelize(
      List(
        ("001", 23),
        ("002", 24),
        ("003", 26),
        ("005", 25)
      )
    )
    /**
     * mapValues: key不变，多value做处理
     */

    val mapValueRDD: RDD[(String, Int)] = idAndAgeRDD.mapValues(age => age + 1)

    mapValueRDD.foreach(println)

    //使用map实现
    idAndAgeRDD.map {
      case (id: String, age: Int) =>
        (id, age + 1)
    }


  }

}
